Completed
Push — develop ( 292cbe...631186 )
by Alexander
15:04
created

manager.js ➔ define   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 132

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 132
rs 8.2857
c 0
b 0
f 0
cc 1
nc 2
nop 2

9 Functions

Rating   Name   Duplication   Size   Complexity  
A manager.js ➔ ... ➔ .removeDraft 0 6 1
A manager.js ➔ ... ➔ .save 0 3 2
A manager.js ➔ ... ➔ .load 0 3 1
A manager.js ➔ ... ➔ .remove 0 7 2
A manager.js ➔ ... ➔ .restoreVersion 0 6 1
A manager.js ➔ ... ➔ .unpublish 0 6 1
A manager.js ➔ ... ➔ .getCopyLocaleUrl 0 5 1
A manager.js ➔ ... ➔ .getVersionsUrl 0 3 1
A manager.js ➔ ... ➔ .copy 0 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/*
2
 * This file is part of the Sulu CMS.
3
 *
4
 * (c) MASSIVE ART WebServices GmbH
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
define(['jquery', 'services/husky/util'], function($, Util) {
11
    'use strict';
12
13
    var templates = {
14
        url: _.template(
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
            '/admin/api/articles' +
16
            '<% if (typeof id !== "undefined") { %>/<%= id %><% } %>' +
17
            '<% if (typeof postfix !== "undefined") { %>/<%= postfix %><% } %>' +
18
            '<% if (typeof version !== "undefined") { %>/<%= version %><% } %>' +
19
            '?locale=<%= locale %>' +
20
            '<% if (typeof action !== "undefined") { %>&action=<%= action %><% } %>' +
21
            '<% if (typeof ids !== "undefined") { %>&ids=<%= ids.join(",") %><% } %>'
22
        )
23
    };
24
25
    return {
26
        url: templates.url,
27
28
        /**
29
         * Load article.
30
         *
31
         * @param {String} id
32
         * @param {String} locale
33
         */
34
        load: function(id, locale) {
35
            return Util.load(templates.url({id: id, locale: locale}));
36
        },
37
38
        /**
39
         * Save article.
40
         *
41
         * @param {Array} data
42
         * @param {String} id
43
         * @param {String} locale
44
         * @param {String} action
45
         */
46
        save: function(data, id, locale, action) {
47
            return Util.save(templates.url({id: id, locale: locale, action: action}), !id ? 'POST' : 'PUT', data);
48
        },
49
50
        /**
51
         * Remove article.
52
         *
53
         * @param {String|Array} id
54
         * @param {String} locale
55
         */
56
        remove: function(id, locale) {
57
            if (typeof id === 'string') {
58
                return Util.save(templates.url({id: id, locale: locale}), 'DELETE');
59
            }
60
61
            return Util.save(templates.url({ids: id, locale: locale}), 'DELETE');
62
        },
63
64
        /**
65
         * Unpublish article.
66
         *
67
         * @param {String} id
68
         * @param {String} locale
69
         */
70
        unpublish: function(id, locale) {
71
            return Util.save(
72
                templates.url({id: id, locale: locale, action: 'unpublish'}),
73
                'POST'
74
            );
75
        },
76
77
        /**
78
         * Remove article.
79
         *
80
         * @param {String} id
81
         * @param {String} locale
82
         */
83
        removeDraft: function(id, locale) {
84
            return Util.save(
85
                templates.url({id: id, locale: locale, action: 'remove-draft'}),
86
                'POST'
87
            );
88
        },
89
90
        /**
91
         * Restore article to given version.
92
         *
93
         * @param {String} id
94
         * @param {String} version
95
         * @param {String} locale
96
         */
97
        restoreVersion: function(id, version, locale) {
98
            return Util.save(
99
                templates.url({id: id, postfix: 'versions', locale: locale, version: version, action: 'restore'}),
100
                'POST'
101
            );
102
        },
103
104
        /**
105
         * Copy given article.
106
         *
107
         * @param {String} id
108
         * @param {String} locale
109
         */
110
        copy: function(id, locale) {
111
            return Util.save(templates.url({id: id, locale: locale, action: 'copy'}), 'POST');
112
        },
113
114
        /**
115
         * Returns copy article from a given locale to a array of other locales url.
116
         *
117
         * @param {String} id
118
         * @param {String} src
119
         * @param {String[]} dest
120
         *
121
         * @returns {String}
122
         */
123
        getCopyLocaleUrl: function(id, src, dest) {
124
            return [
125
                templates.url({id: id, locale: src, action: 'copy-locale'}), '&dest=', dest
126
            ].join('');
127
        },
128
129
        /**
130
         * Returns get versions url for given id and locale.
131
         *
132
         * @param {String} id
133
         * @param {String} locale
134
         *
135
         * @return {String}
136
         */
137
        getVersionsUrl: function(id, locale) {
138
            return templates.url({id: id, postfix: 'versions', locale: locale});
139
        }
140
    };
141
});
142